var _timer = 30000;
var _split = 1;
var _id = 0;
var _status = "资料读取中...";

var g_numcolor = [0,1,1,2,2,3,3,1,1,2,2,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,2,2,3,3,1,1,2,2,3];
var colors = ["","red", "blue", "green"];
var c_bignum = ["","一","二","三","四","五","六"];
var c_betname = ["","单","双", "大", "小", "红波", "蓝波", "绿波","合单","合双"];
var XH = null;
var XH1= null;
if (window.XMLHttpRequest)
{// code for all new browsers
    XH = new XMLHttpRequest();
    XH1 = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
  XH = new ActiveXObject("Microsoft.XMLHTTP");
  XH1 = new ActiveXObject("Microsoft.XMLHTTP");
} else 
  alert("Your browser does not support XMLHTTP.");

var timer_id;
var chkbutmod = false;
var b151_num = 0;
var b152_num = 0;
var b153_num = "";
var account = "";
//   Math.round(n) = 去小数取整数，Math.floor(n) = 四舍五入到整数

function getcontent()
{
    XH.open("POST", "op.php?op=xml&fp=unow22&id="+_id+"&split="+_split,false); 
    try{XH.send("");return XH.responseText; }catch(E){}
}

function timer()
{
	window.status = _status;
	var i, j;
	var str = getcontent();
	if (str=="") { alert("Error 1"); }
	if (str=="-1") { location.reload(); }

	var a = str.split("\n");
	j = 0;
	for (i=1; i<7; i++) {
		show_rate15(2, i, a[j++]);
		show_rate15(4, i, a[j++]);
		show_rate17(7 ,i, a[j++]);
		show_rate23(9 ,i, a[j++]);
	}
	show_titleAmu(a[j++]);
	window.status = "";

	// timer_id = setTimeout("timer()", _timer);
}

function show_rate23(t, j, str)
{
	var i,ii,k;
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<3; i++) {
		bt = 23;
		ii = i+7;
		k = bt+"_"+j+"_"+ii;
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		nms = j+" "+ii;
		document.all["rate_"+k].innerHTML = rate;
		//if (count > 0) {
			document.all["amount_"+k].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype="+bt+"&numbers="+escape(nms)+">"+Math.floor(amount)+"</a>";
			document.all["chg_"+k].innerHTML = "<input type=checkbox id=rrr_"+k+" onclick=\"quickrrr('"+k+"')\">";
		/*
		} else {
			document.all["amount_"+k].innerHTML = Math.floor(amount);
			document.all["chg_"+k].innerHTML = "<input disabled type=checkbox id=rrr_"+k+">";
		}
		*/
		win1 = Math.floor(win - a00[3]);
		document.all["win_"+k].innerHTML = win1;
		document.all["win_"+k].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	//document.all["total23_"+j+"_"+t].innerHTML=Math.floor(amount0);
}

function show_rate17(t, j, str)
{
	var i,ii,k;
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<4; i++) {
		bt = 17;
		ii = i+4;
		k = bt+"_"+j+"_"+ii;
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		nms = j+" "+ii;
		document.all["rate_"+k].innerHTML = rate;
		//if (count > 0) {
			document.all["amount_"+k].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype="+bt+"&numbers="+escape(nms)+">"+Math.floor(amount)+"</a>";
			document.all["chg_"+k].innerHTML = "<input type=checkbox id=rrr_"+k+" onclick=\"quickrrr('"+k+"')\">";
		/*
		} else {
			document.all["amount_"+k].innerHTML = Math.floor(amount);
			document.all["chg_"+k].innerHTML = "<input disabled type=checkbox id=rrr_"+k+">";
		}
		*/
		win1 = Math.floor(win - a00[3]);
		document.all["win_"+k].innerHTML = win1;
		document.all["win_"+k].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	//document.all["total17_"+j+"_"+t].innerHTML=Math.floor(amount0);
}

function show_rate15(t, j, str)
{
	var i,ii,k;
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<3; i++) {
		bt = (t==2 ? 15 : 16);
		ii = (bt==16 ? i+2 : i);
		k = bt+"_"+j+"_"+ii;
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		nms = j+" "+ii;
		document.all["rate_"+k].innerHTML = rate;
		//if (count > 0) {
			document.all["amount_"+k].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype="+bt+"&numbers="+escape(nms)+">"+Math.floor(amount)+"</a>";
			document.all["chg_"+k].innerHTML = "<input type=checkbox id=rrr_"+k+" onclick=\"quickrrr('"+k+"')\">";
		/*
		} else {
			document.all["amount_"+k].innerHTML = Math.floor(amount);
			document.all["chg_"+k].innerHTML = "<input disabled type=checkbox id=rrr_"+k+">";
		}
		*/
		win1 = Math.floor(win - a00[3]);
		document.all["win_"+k].innerHTML = win1;
		document.all["win_"+k].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
	//document.all["total15_"+j+"_"+t].innerHTML=Math.floor(amount0);
}
function show_titleAmu(str)
{
	var a0 = str.split(",");
	var i = 0;
	var l = a0.length;
	var amu = 0;
	var clr = '';
	var oObj = '';
	for (i=0; i<l; i++) {
		a00 = a0[i].split("@");
		amu = a00[0];
		if(a00[1] > 0){ clr = '#ffff99';  }else{ clr = 'transparent';  }
    oObj = document.getElementById("menuAmu"+i);
    oObj.innerHTML = amu;
    oObj.style.backgroundColor = clr;
	}
}
function quickrrr(k)
{
	if (document.all["rrr_"+k].checked) {
		if (!chkbutmod) {
			chkbutmod = true;
		}
		if (timer_id) clearTimeout(timer_id);
		// timer_id = setTimeout("timer()", 60000);
	}
}

function gen_rate15()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center><td rowspan=2></td>"
		+"<td colspan=4>"+_name3[1]+"</td><td colspan=4>"+_name3[2]+"</td>"
		+"<td colspan=4>"+_name3[3]+"</td><td colspan=4>"+_name3[4]+"</td></tr><tr class=td0 align=center>";
	
	for (i=0; i<4; i++) ret += _tb15head;
	ret += "</tr>";
	
	for (j=1; j<7; j++) {
		ret += "<tr class=td2 align=right><td class=td15 nowrap align=center>"+_name4+_name5[j]+"</td>";
		for (i=1; i<5; i++) {
			k = (i < 3 ? 15 : 16)+"_"+j+"_"+i;
			ret += "<td nowrap id=amount_"+k+"></td><td nowrap id=win_"+k+"></td><td id=rate_"+k+" class=rate></td><td align=center id=chg_"+k+"></td>";
			//if (i==2 || i==4) {
			//	ret += "<td class=td6 id=total15_"+j+"_"+i+"></td>";  // <td rowspan=2>"+_total+"</td>
			//}
		}
	}
	ret += "</table>";
	document.all.div15.innerHTML = ret;
}

function gen_rate17()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center><td rowspan=2></td>"
		+"<td colspan=4>"+_name3[5]+"</td><td colspan=4>"+_name3[6]+"</td>"
		+"<td colspan=4>"+_name3[7]+"</td>"
		+"<td colspan=4>"+_name3[8]+"</td><td colspan=4>"+_name3[9]+"</td></tr><tr class=td0 align=center>";
	
	for (i=0; i<5; i++) ret += _tb15head;
	ret += "</tr>";
	
	for (j=1; j<7; j++) {
		ret += "<tr class=td2 align=right><td class=td15 nowrap align=center>"+_name4+_name5[j]+"</td>";
		for (i=5; i<10; i++) {
			k = (i<8 ? 17 : 23)+"_"+j+"_"+i;
			ret += "<td nowrap id=amount_"+k+"></td><td nowrap id=win_"+k+"></td><td id=rate_"+k+" class=rate></td><td align=center id=chg_"+k+"></td>";
			//if (i==7 || i==9) {
			//	ret += "<td class=td6 id=total"+k+"></td>";  // <td rowspan=2>"+_total+"</td>
			//}
		}
	}
	ret += "</table>";
	document.all.div17.innerHTML = ret;
}

function protect_b1()
{
	var cc = "";
	var bt = 0;
	var ii = 0;
	var kk = "";
	var count = 0;
	var _bet = new Array();
	var _cod = new Array();
	var _num = new Array();
	b151_num = document.all.b151.value-0;
	b152_num = document.all.b152.value-0;
	b153_num = document.all.b153.value-0;
	account = document.all.usr1.value;
	if (b151_num <= 0) {
		alert("赔率不可为 0.");
	} else if (b151_num > 3.5) {
		alert("不合理的赔率数值！");
	} else if (b152_num > 5) {
		alert("不合理的退水数值！");
	} else {
		SetCookie("b151", document.all.b151.value);
		SetCookie("b152", document.all.b152.value);
		if (b153_num > 0) {
			for (j=1; j<7; j++) {
				for (i=1; i<3; i++) {
					bt = 23;
					ii = i+7;
					kk = bt+"_"+j+"_"+ii;
					if (document.all["rrr_"+kk].checked) {
						//if (document.all["amount_"+kk].innerHTML-0 >= b153_num) {
							_bet[count] = bt;
							_cod[count] = j;
							_num[count] = ii;
							cc += "正码"+c_bignum[j]+"："+c_betname[ii]+"  →  "+b153_num+"\n";
							count++;
						//}
					}
				}
			}
			for (j=1; j<7; j++) {
				for (i=1; i<4; i++) {
					bt = 17;
					ii = i+4;
					kk = bt+"_"+j+"_"+ii;
					if (document.all["rrr_"+kk].checked) {
						//if (document.all["amount_"+kk].innerHTML-0 >= b153_num) {
							_bet[count] = bt;
							_cod[count] = j;
							_num[count] = ii;
							cc += "正码"+c_bignum[j]+"："+c_betname[ii]+"  →  "+b153_num+"\n";
							count++;
						//}
					}
				}
			}
			for (j=1; j<7; j++) {
				for (i=1; i<3; i++) {
					bt = 16;
					ii = i+2;
					kk = bt+"_"+j+"_"+ii;
					if (document.all["rrr_"+kk].checked) {
						//if (document.all["amount_"+kk].innerHTML-0 >= b153_num) {
							_bet[count] = bt;
							_cod[count] = j;
							_num[count] = ii;
							cc += "正码"+c_bignum[j]+"："+c_betname[ii]+"  →  "+b153_num+"\n";
							count++;
						//}
					}
				}
			}
			for (j=1; j<7; j++) {
				for (ii=1; ii<3; ii++) {
					bt = 15;
					kk = bt+"_"+j+"_"+ii;
					if (document.all["rrr_"+kk].checked) {
						//if (document.all["amount_"+kk].innerHTML-0 >= b153_num) {
							_bet[count] = bt;
							_cod[count] = j;
							_num[count] = ii;
							cc += "正码"+c_bignum[j]+"："+c_betname[ii]+"  →  "+b153_num+"\n";
							count++;
						//}
					}
				}
			}
			if (count > 0) {
				if (confirm("正码1~6 走飞内容\n———————————  \n"+cc+"———————————  \n合计 "+count+" 笔\n\n是否确定走飞？")) {
					XH1.open("POST", "op.php?op=admin&fp=protsaves2&id="+_id+"&bt="+_bet+"&cn="+_cod+"&num="+_num+"&rate="+b151_num+"&back="+b152_num+"&nts="+b153_num+"&acc="+account, false); 
					try{XH1.send("");}catch(E){}
					window.status = "";
					alert("走飞完成");
				}
			}
		}
	}
	b151_num = "";
	b152_num = "";
	b153_num = "";
	document.all.b151.value = b151_num;
	document.all.b152.value = b152_num;
	document.all.b153.value = b153_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function w(s) {
	document.write(s);
}

function winonload()
{
	gen_rate15();
	gen_rate17();

	b151_num = document.all.b151.value-0.00;
	b152_num = document.all.b152.value-0.00;
	b153_num = document.all.b153.value-0;
	account = document.all.usr1.value;
	chkbutmod = false;
	timer();
}

window.onload = winonload;